%{
    #include <stdlib.h>
    #include "clausspilator.tab.h"

    int nline = 1;
%}
ident [a-zA-Z][_a-zA-Z0-9]*
int [0-9]+
float [0-9]+\.[0-9]*
chaine \"([^"]*|\\\")\"

%x COMMENT
%x ONELINE_COMMENT
%x CHAINE
%%
"//"                    { BEGIN ONELINE_COMMENT; }
<ONELINE_COMMENT>.      { }
<ONELINE_COMMENT>"\n"   { BEGIN INITIAL; nline++; }

"/*"            { BEGIN COMMENT; }
<COMMENT>"\n"   { nline++; }
<COMMENT>.      { }
<COMMENT>"*/"   { BEGIN INITIAL; }

"\n"    { nline++; }

main    { return MAIN; }
int     { return INT_T; }
float   { return FLOAT_T; }
bool    { return BOOL_T; }
scanf   { return READ; }
printf  { return WRITE; }
if      { return IF; }
else    { return ELSE; }
for     { return FOR; }
while   { return WHILE; }
return  { return EXIT; }
true    { yylval.nombre = 1;return TRUE; }
false   { yylval.nombre = 0;return FALSE; }

"+="  { return PLUS_EGAL;}
"++"  { return PLUS_PLUS; }
"-="  { return MOINS_EGAL; }
"--"  { return MOINS_MOINS; }

">="  { return GE; }
"<="  { return LE; }
"=="  { return EQ; }
"!="  { return NE; }
"&&"  { return AND;}
"||"  { return OR; }

[-+/><=();{?#:}*&,!%] { return *yytext; }
[ \t]+   /* Nothing to do here */

{chaine}        { yylval.chaine = strdup(yytext); return STRING; }
{ident}         { yylval.chaine = strdup(yytext);return IDENT; }
{float}         { yylval.reel = (float)atof(yytext); return FLOAT; }
{int}           { yylval.nombre = atoi(yytext);return INT; }

.               {
                    char tmp[50];
                    sprintf( tmp , "Unknown character \"%c\"", *yytext);
                    yyerror( tmp );
                }
%%
int yywrap() {
    return(1);
}
